package com.attendance.www.hr.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.attendance.www.hr.beans.FurloughBean;
import com.attendance.www.hr.dao.mapper.FurloughExtMapper;
import com.attendance.www.hr.dao.mapper.FurloughMapper;
import com.attendance.www.hr.entitys.Furlough;
import com.attendance.www.hr.entitys.FurloughExample;
import com.attendance.www.hr.service.IFurloughService;

@Service
public class FurloughServiceImpl implements IFurloughService {
	@Resource
	private FurloughExtMapper FurloughExtDao;

	@Resource
	private FurloughMapper FurloughDao;

	@Override
	public List<FurloughBean> getFurloughList() {
		return FurloughExtDao.getFurloughList();
	}
	/**
	 * 添加休假设置
	 */
	@Override
	public boolean saveFurlough(FurloughBean furloughBean) {
		Furlough furlough = new Furlough();
		furlough.setFurloughType(furloughBean.getFurloughType());
		furlough.setDayNumber(furloughBean.getDayNumber());
		int record = FurloughDao.insertSelective(furlough);
		if (record > 0) {
			return true;
		} else {
			return false;
		}
	}
	/**
	 * 更新休假设置
	 */
	@Override
	public boolean updateFurlough(FurloughBean furloughBean) {
		Furlough furlough = new Furlough();
		furlough.setFurloughId(furloughBean.getFurloughId());
		furlough.setFurloughType(furloughBean.getFurloughType());
		furlough.setDayNumber(furloughBean.getDayNumber());
		int record = FurloughDao.updateByPrimaryKeySelective(furlough);
		if (record > 0) {
			return true;
		} else {
			return false;
		}
	}
	/**
	 * 删除休假设置
	 */
	@Override
	public boolean deleteFurlough(Integer furloughId) {
		int record = FurloughDao.deleteByPrimaryKey(furloughId);
		if (record > 0) {
			return true;
		} else {
			return false;
		}
	}
	/**
	 * 获取休假设置
	 */
	@Override
	public boolean getFurloughByFurlough(FurloughBean furloughBean) {
		FurloughExample example = new FurloughExample();
		FurloughExample.Criteria criteria = example.createCriteria();
		criteria.andFurloughTypeEqualTo(furloughBean.getFurloughType());
		List<Furlough> furloughList = FurloughDao.selectByExample(example);
		if (furloughList.size() > 0) {
			return true;
		} else {
			return false;
		}
	}
	/**
	 * 根据ID查找休假设置
	 */
	@Override
	public Furlough getFurloughListById(Integer furloughId) {
		FurloughExample example = new FurloughExample();
		FurloughExample.Criteria criteria = example.createCriteria();
		criteria.andFurloughIdEqualTo(furloughId);
		List<Furlough> furloughList = FurloughDao.selectByExample(example);
		if (furloughList.size() > 0) {
			return furloughList.get(0);
		} else {
			return null;
		}

	}

}
